package piece1.chapter5;

public class Problem5_15 {

    /**
     * @param args
     */

    public static void main(String[] args) {
	// TODO 自动生成的方法存根
	double num[] = new double[100000];
	long startTime = System.nanoTime();
	for (int i = 0; i < num.length; i++) {
	    num[i] = Math.random() * 10000;

	}
	long endTIme = System.nanoTime();
	System.out.println("赋值经过了" + (endTIme - startTime) + "ns");
	startTime = System.currentTimeMillis();
	QuickSort(num, 0, num.length - 1);
	endTIme = System.currentTimeMillis();
	System.out.println("排序经过了" + (endTIme - startTime) + "ms");

    }

    public static void QuickSort(double q[], int left, int right) {
	int i = left + 1, j = right;
	double m = q[left];
	double temp;
	// //
	while (i <= j) {
	    while (q[i] <= m && i <= j)
		i++;
	    while (q[j] >= m && i <= j)
		j--;
	    if (i < j) {
		temp = q[i];
		q[i] = q[j];
		q[j] = temp;
		i++;
		j--;
	    }
	}
	// ///
	if (j != left) {
	    temp = q[j];
	    q[j] = m;
	    q[left] = temp;
	}
	// System.out.println(j);
	// System.out.println("i:" + i);

	if (j - 1 > left)
	    QuickSort(q, left, j - 1);
	if (j + 1 < right)
	    QuickSort(q, j + 1, right - 1);
    }
}
